// https://www.acwing.com/problem/content/5/

#include <iostream>
#include <vector>

using namespace std;

int solution(vector<int> volumes, vector<int> values, int maxVolume) {
    vector<int> dp(maxVolume + 1);
    dp[0] = 0;
    for (int i = 0; i < values.size(); i++) {
        for (int v = maxVolume; v >= volumes[i]; v--) {
            dp[v] = max(dp[v], dp[v-volumes[i]] + values[i]);
        }
    }
    return dp[maxVolume];
}

vector<int> convertVector(vector<int>& keys, vector<int>& counts) {
    vector<int> results;
    for (int i=0; i<keys.size(); i++) {
        int count = counts[i];
        int key = keys[i];

        for (int j=1; j <= count; j *= 2) {
            results.push_back(key * j);
            count -= j;
        }

        if (count >= 0) {
            results.push_back(key * count);
        }
    }
    return results;
}

int main() {
    int n, maxVolume;
    cin>>n>>maxVolume;
    vector<int> volumes(n);
    vector<int> values(n);
    vector<int> valueCounts(n);
    for (int i=0; i<n; i++) {
        cin>>volumes[i]>>values[i]>>valueCounts[i];
    }

    vector<int> convertVolumes = convertVector(volumes, valueCounts);
    vector<int> convertValues = convertVector(values, valueCounts);
    cout<<solution(convertVolumes, convertValues, maxVolume)<<endl;

    return 0;
}
